boolean isP10(n) {
    s = n.toString()
    s == s.reverse()
}

boolean isP2(n) {
    s = Integer.toBinaryString(n)
    s == s.reverse()
}

def sum = 0
(0..<1000000).each { n -> if (isP2(n) && isP10(n)) sum += n }
println sum
